package com.ruoyi.project.communication.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.communication.domain.UserCommunication;
import com.ruoyi.project.communication.service.IUserCommunicationService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 用户交流Controller
 * 
 * @author Daniel
 * @date 2020-04-03
 */
@RestController
@RequestMapping("/communication/communication")
public class UserCommunicationController extends BaseController
{
    @Autowired
    private IUserCommunicationService userCommunicationService;

    /**
     * 查询用户交流列表
     */
    @PreAuthorize("@ss.hasPermi('communication:communication:list')")
    @GetMapping("/list")
    public AjaxResult list(UserCommunication userCommunication)
    {
        List<UserCommunication> list = userCommunicationService.selectUserCommunicationList(userCommunication);
        return AjaxResult.success(list);
    }

    /**
     * 查询根用户交流列表
     */
//    @PreAuthorize("@ss.hasPermi('communication:communication:list')")
    @GetMapping("/getRoot")
    public AjaxResult getRoot()
    {
        List<UserCommunication> list = userCommunicationService.getRoot();
        return AjaxResult.success(list);
    }

    /**
     * 导出用户交流列表
     */
    @PreAuthorize("@ss.hasPermi('communication:communication:export')")
    @Log(title = "用户交流", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UserCommunication userCommunication)
    {
        List<UserCommunication> list = userCommunicationService.selectUserCommunicationList(userCommunication);
        ExcelUtil<UserCommunication> util = new ExcelUtil<UserCommunication>(UserCommunication.class);
        return util.exportExcel(list, "communication");
    }

    /**
     * 获取用户交流详细信息
     */
    @PreAuthorize("@ss.hasPermi('communication:communication:query')")
    @GetMapping(value = "/{ucId}")
    public AjaxResult getInfo(@PathVariable("ucId") Long ucId)
    {
        return AjaxResult.success(userCommunicationService.selectUserCommunicationById(ucId));
    }

    /**
     * 新增用户交流
     */
    @PreAuthorize("@ss.hasPermi('communication:communication:add')")
    @Log(title = "用户交流", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserCommunication userCommunication)
    {
        return toAjax(userCommunicationService.insertUserCommunication(userCommunication));
    }

    /**
     * 修改用户交流
     */
    @PreAuthorize("@ss.hasPermi('communication:communication:edit')")
    @Log(title = "用户交流", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserCommunication userCommunication)
    {
        return toAjax(userCommunicationService.updateUserCommunication(userCommunication));
    }

    /**
     * 删除用户交流
     */
    @PreAuthorize("@ss.hasPermi('communication:communication:remove')")
    @Log(title = "用户交流", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ucIds}")
    public AjaxResult remove(@PathVariable Long[] ucIds)
    {
        return toAjax(userCommunicationService.deleteUserCommunicationByIds(ucIds));
    }
}
